#! usr/bin/python3

import rospy
from sensor_msgs.msg import PointCloud2

class Mypcd():
    def __init__(self, node_name="pcd_transfer"):
        rospy.init_node(node_name, anonymous=False)
        self.pcd2 = PointCloud2()
        self.pcd2_sub = rospy.Subscriber("/robot1/pandar",PointCloud2,self.cb_pcd)
        self.pcd2_pub = rospy.Publisher("/mypcd",PointCloud2,queue_size=10)

        self.pcd2_hz = 30

        self.publish_pcd()

    def cb_pcd(self, data):
        self.pcd2 = data
        self.pcd2.header.frame_id = "map"
        # print(self.pcd2)

    def pcd_pub_timer_cb(self, event):
        self.pcd2_pub.publish(self.pcd2)
        # print("我在发东西")

    def publish_pcd(self):
        self.pcd_pub_timer = rospy.Timer(rospy.Duration(1/self.pcd2_hz), self.pcd_pub_timer_cb)


if __name__ == "__main__":
    pcd_trans = Mypcd()
    rospy.spin()